package com.ejd.web.vo.genl;

import java.util.List;


import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.ICollarService;
import com.ejd.service.IMaterialService;
import com.ejd.service.IPatternService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Collar;
import com.ejd.web.bo.impl.Material;
import com.ejd.web.bo.impl.Pattern;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existCollar")
@SessionScoped
public class ExistCollarBean implements java.io.Serializable {

	private SelectItem[] collarItems;



	public SelectItem[] getCollarItems() {
		return collarItems;
	}



	public void setCollarItems(SelectItem[] collarItems) {
		this.collarItems = collarItems;
	}



	public ExistCollarBean() {
		
		ICollarService<Collar,Long> collarService = (ICollarService<Collar,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.COLLAR_SERVICE_BEAN_NAME);
		collarService.setEntityClass(Collar.class);
		collarService.setPKClass(Long.class);
		List<Collar> collars = collarService.getAll();
		SelectItem[] tempCollarItems = new SelectItem[collars.size()];
		if (null != collars && !(collars.isEmpty())) {
			for (int i=0; i< tempCollarItems.length; i++) {
				Collar collar = (Collar) collars.get(i);
				String materialNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,collar.getCollarName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempCollarItems[i] = new SelectItem(collar.getCollarCode(),materialNameN18);
			}
		}
		this.setCollarItems(tempCollarItems);
	}
}
